/**
 * 
 */
package belote.webapp.struts.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import belote.service.user.Genre;
import belote.service.user.User;
import belote.service.user.UserService;
import belote.service.user.UserServiceFactory;

/**
 * @author Gwenn
 * 
 */
public class RegistrationSubmitAction extends Action {

	private final UserService userService = UserServiceFactory.getUserService();

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ActionForward execute(ActionMapping pMapping, ActionForm pForm, HttpServletRequest pRequest, HttpServletResponse pResponse) throws Exception {

		RegistrationForm inscForm = (RegistrationForm) pForm;

		// Creation de l'utilisateur
		User user = new User();
		user.setLogin(inscForm.getLogin());
		user.setPassword(inscForm.getPassword());
		user.setEmail(inscForm.getEmail());
		user.setGenre(Genre.getGenre(inscForm.getGenre()));

		// Sauvegarde de l'utilisateur
		userService.insert(user);

		return pMapping.findForward("success");
	}
}
